<?php 
require_once (dirname(__FILE__)."/services.php");
class projects_RouterExtension extends Extension {
    public function apply(&$context, Chain $chain) {
        $context['rule']['{^/projects/*$}'] = dirname(__FILE__)."/actions.php";
        $context['rule']['{^/projects/(\w+)/$}'] = dirname(__FILE__)."/actions.php";
        $chain->next($context);
    }
}

class projectsFeature extends Feature {
    public function registerExtension() {
        $this->extensions = Array( 
              	 new projects_RouterExtension("com.yizin.platform.router")
		);
    }
    
    public function registerExtendable() {
    }
    
    public function init() {
    	$conn = getDBConnection();
		$conn->query('drop table if exists projects;');
		$conn->query('drop table if exists projects_profiles;');
		
		$query_projects = 'CREATE TABLE projects (
			id_project BIGINT PRIMARY KEY AUTO_INCREMENT,
			title VARCHAR(255) NOT NULL,
			short_title VARCHAR(255) NOT NULL,
			start_time VARCHAR(255) NULL,
			logo VARCHAR(255) NULL,
			owner BIGINT NULL
		)CHARSET=utf8;';
		
		$query_projects_profiles = 'CREATE TABLE projects_profiles (
			id BIGINT PRIMARY KEY AUTO_INCREMENT,
			id_project BIGINT NOT NULL,
			profile_key VARCHAR(255) NOT NULL,
			profile_value TEXT NULL
		)CHARSET=utf8;';
		
    	$conn->query($query_projects);
		$conn->query($query_projects_profiles);
		
		$conn->disconnect();
	}
    
    public function destroy() {
    	$conn=getDBConnection();
		
		$conn->query('drop table if exists projects;');
		$conn->query('drop table if exists projects_profiles;');
		
		$conn->disconnect();
    }
}

$featureClass = "projectsFeature";
$featureName = "projects";
$featureIntroduction = "projects feature";
?>
